﻿using System.Xml.Linq;
using Maple.Weixin.MP.Helpers;

namespace Maple.Weixin.MP.Entities.Messages
{
    public sealed class RequestMessageEventLocation : RequestMessageEventBase
    {
        public override Event Event
        {
            get { return Event.LOCATION; }
        }

        /// <summary>
        /// 地理位置维度，事件类型为LOCATION的时存在
        /// </summary>
        public double Latitude { get; private set; }
        /// <summary>
        /// 地理位置经度，事件类型为LOCATION的时存在
        /// </summary>
        public double Longitude { get; private set; }
        /// <summary>
        /// 地理位置精度，事件类型为LOCATION的时存在
        /// </summary>
        public double Precision { get; private set; }

        protected override void FillPropertiesByXml(XDocument document)
        {
            base.FillPropertiesByXml(document);
            this.Latitude = double.Parse(document.GetElementValue("Latitude", true));
            this.Longitude = double.Parse(document.GetElementValue("Longitude", true));
            this.Precision = double.Parse(document.GetElementValue("Precision", true));
        }

        public override T Accept<T>(RequestMessageVisitor<T> visitor) {
            return visitor == null ? default(T) : visitor.Visit(this);
        }
    }
}
